#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017-11-07 16:12
# @Author  : zejin
# @File    : urllibtest.py

from urllib import parse
from urllib import request
from bs4 import BeautifulSoup


# req = request.Request("http://www.thsrc.com.tw")
req = request.Request("http://www.thsrc.com.tw/tw/TimeTable/SearchResult")

postData = parse.urlencode([
    ("StartStation", "2f940836-cedc-41ef-8e28-c2336ac8fe68"), ("EndStation", "977abb69-413a-4ccf-a109-0272c24fd490"),
    ("SearchDate", "2017/11/07"), ("SearchTime", "17:30"), ("SearchWay", "DepartureInMandarin")
])




# 添加来源信息和浏览器信息反爬虫识别
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36")
req.add_header("Origin","http://www.thsrc.com.tw")
resp = request.urlopen(req,data=postData.encode("utf-8"))


print(resp.read().decode("utf-8"))

